package com.zhangdi.demo.date;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.StopWatch;
import cn.hutool.core.map.MapUtil;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

/**
 * Created by zhangdi on 2020/06/12 16:03:06.
 */
public class FriendlyDate {
    private static final String DATE_FORMAT_YMD_HM = "yyyy-MM-dd HH:mm";

    public static String formatFriendlyShowTime(Date date) {
        long span = (new Date().getTime() - date.getTime()) / 1000;
        if (span < 0 || span / (60 * 60 * 24 * 30) > 0) {
            return DateFormatUtils.format(date, DATE_FORMAT_YMD_HM);
        } else if (span / (60 * 60 * 24 * 7) > 0) {
            return span / (60 * 60 * 24 * 7) + "周前";
        } else if (span / (60 * 60 * 24) > 0) {
            return span / (60 * 60 * 24) + "天前";
        } else if (span / (60 * 60) > 0) {
            return span / (60 * 60) + "小时前";
        } else if (span / (60) > 0) {
            return span / (60) + "分钟前";
        }

        return "刚刚";
    }

    public static void main(String[] args) {
//        Date d1 = new Date("Wed Jul 08 18:00:00 CST 2021");
//        Date d2 = new Date("Wed Jul 06 16:00:00 CST 2022");
//        System.out.println(DateUtil.beginOfDay(d1).after(DateUtil.beginOfDay(d2)));
//        System.out.println(DateUtil.compare(d1, d2, "yyyy-MM-dd"));
//        System.out.println(DateUtil.dayOfYear(d1));
//        System.out.println(DateUtil.dayOfYear(d2));
//        System.out.println(DateUtil.parse("2023-07-15").getTime());

//        Map<String, String> aaa = new ConcurrentHashMap<>();
//        aaa.put("b", "2");
//        System.out.println(aaa.containsKey("b"));
//        String a = aaa.putIfAbsent("b", "4");
//        System.out.println(a);
//
//        System.out.println(aaa.get("b"));

        List<Integer> aa = new ArrayList<>();
        aa.add(0);
        aa.add(1);
        aa.add(2);

        List<Integer> b = aa.subList(0, 2);

        System.out.println(b.size());
        System.out.println(aa.size());


    }

//    public static void main(String[] args) {
//        System.out.println(FriendlyDate.formatFriendlyShowTime(new Date()));
//    }

//    public static void main(String[] args) throws ParseException {
//        Date date = new Date("Wed Jul 06 00:00:00 CST 2022");
//       SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.US);
//       Date date1 = sdf.parse(sdf.format(date));
//       sdf = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
//        Date date2 = sdf.parse(sdf.format(date1));
//        System.out.println(date2);
//Date ddd = new Date(1657098201000L);
//
//        System.out.println(sdf.parse(sdf.format(ddd)));
//
////        Date time = new Date(1646905290000L);
////        Calendar calendar = Calendar.getInstance();
////        calendar.setTime(time);
////        calendar.add(Calendar.HOUR_OF_DAY, 24);
////
////        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
////        System.out.println(sdf.format(calendar.getTime()));
//
//        Calendar calendar = Calendar.getInstance();
//        Date time = new Date();
//        System.out.println(time);
//        calendar.setTime(time);
//        calendar.add(Calendar.DAY_OF_MONTH, 30);
//        time = calendar.getTime();
//        System.out.println(time);
//
////        Date date = new Date();
////        Calendar calendar = Calendar.getInstance();
////        calendar.setTime(date);
//////        calendar.set(Calendar.HOUR_OF_DAY, 23);
//////        calendar.set(Calendar.MINUTE, 59);
//////        calendar.set(Calendar.SECOND, 59);
////        calendar.add(Calendar.DAY_OF_YEAR, 400);
////
////        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
////        System.out.println(sdf.format(calendar.getTime()));
//
////        int i = 0;
////        while (true) {
////            if(i == 10) {
////                return;
////            }
////            i++;
////            if(i == 10) {
////                continue;
////            }
////            System.out.println(i);
////
////        }
//
////        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
////        Date date1 = df.parse("2020-10-17 23:59:59.0");
////        System.out.println(date1.toString());
////        try {
////            int i = 2/0;
////        }catch (Exception e){
////            e.printStackTrace();
////            System.out.println(e.getMessage());
////        }
////
////        System.out.println(222);
//    }
}
